package Environment;

/**
 * A type of boundary that stretches infinitely on the x and y 
 * directions. If a moving object comes hits on a wall, it'll 
 * come out the other side with the same velocity. 
 * 
 * @author - Ga-Young Joung and Perry Zheng
 */

import java.awt.Dimension;
import java.util.ArrayList;

import utilities.Vector;

public class InfiniteBoundary implements Boundary {

	private Environment myEnvironment;

	/**
	 * Creates a Boundary object acting as it's got infinite dimensions
	 * 
	 * @param environment  The environment to which the boundary is supposed to enclose
	 */
	public InfiniteBoundary(Environment environment) {
		myEnvironment = environment;
	}

	/**
	 * Return the new Position and new Velocity of the object when a moving
	 * entity hits the boundary
	 * @param center  the current center of the object
	 * @param velocity  the current velocity of the moving object
	 * @param sizeOfEntity  the size (radius, for instance) of the moving object
	 * @return - The new position and velocity of the moving object after the 
	 * moving entity hits the boundary. 
	 */
	public ArrayList<Vector> getNewPositionAndVelocity(Vector center,
			Vector velocity, Dimension sizeOfEntity) {
		Vector newVelocity = new Vector(velocity);
		Vector newCenter = center.add(velocity);
		Dimension size = myEnvironment.getSize();
		if (center.x < 0) {
			newCenter.x = size.width + center.x;
		} else if (center.x > size.width) {
			newCenter.x = center.x - size.width;
		}
		if (center.y < 0) {
			newCenter.y = size.height + center.y;
		} else if (center.y > size.height) {
			newCenter.y = center.y - size.height;
		}
		ArrayList<Vector> list = new ArrayList<Vector>();
		list.add(newVelocity);
		list.add(newCenter);
		return list;
	}
}
